export default ({ http }) => ({
  // 获取白板oss配置
  getLiveAgoraNetless(response) {
    return http.get('course/live/agora/netless', {}, response)
  },
  /**
   * @description 获取声网配置
   */
  setLiveRoomStart(params, response) {
    return http.post('/course/live/room/start', params, response)
  },
  setLiveRoomEnd(params, response) {
    return http.post('/course/live/room/end', params, response)
  },
  /**
   * @description 获取声网配置
   */
  getLiveAgoraConfig(response) {
    return http.get('/course/live/agora/config', {}, response)
  },
  // 获取互动课堂用户签名
  getCourseTencent(params, response) {
    return http.get('/course/live/tencent/v2/userSig', params, response)
  },
  // 获取声网课堂用户房间信息
  getLiveAgoraRoomInfo(id, response) {
    return http.get(`/course/live/agora/room/${id}`, {}, response, {}, false)
  },
  // 直播带货课程
  getLiveCourse(params, response) {
    return http.get(`/course/live/room/coursedatas`, params, response)
  },
  // 进入房间
  async entry(appid, params, auth) {
    return await http.post(
      `https://api.agora.io/edu/v1/apps/${appid}/room/entry`,
      params,
      res => {
        return res.data
      },
      {},
      true,
      {
        headers: {
          Authorization: auth
        }
      }
    )
  },
  // 进入房间
  async getCourseRecordBy(appid, roomId, recordId, auth, token) {
    return await http.get(
      `https://api.agora.io/edu/v1/apps/${appid}/room/${roomId}/record/${recordId}`,
      {},
      res => {
        return res.data
      },
      {},
      true,
      {
        headers: {
          Authorization: auth,
          token: token
        }
      }
    )
  },
  // 白板
  async getWhiteboardBy(appid, roomId, auth, token) {
    return await http.get(
      `https://api.agora.io/edu/v1/apps/${appid}/room/${roomId}/board`,
      {},
      res => {
        return res.data
      },
      {},
      true,
      {
        headers: {
          Authorization: auth,
          token: token
        }
      }
    )
  },
  // 获取房间信息
  async getRoomInfoBy(appid, roomId, auth, token) {
    return await http.get(
      `https://api.agora.io/edu/v1/apps/${appid}/room/${roomId}`,
      {},
      res => {
        return res.data
      },
      {},
      true,
      {
        headers: {
          Authorization: auth,
          token: token
        }
      }
    )
  },
  // 发送聊天消息
  async sendChannelMessage(appid, payload, auth, token) {
    return await http.post(
      `https://api.agora.io/edu/v1/apps/${appid}/room/${payload.roomId}/chat`,
      {
        message: payload.message,
        type: payload.type
      },
      res => {
        return res.data
      },
      {},
      false,
      {
        headers: {
          Authorization: auth,
          token: token
        }
      }
    )
  },
  // 更新用户状态，老师可更新房间内所有人，学生只能更新自己
  async updateRoomUser(appid, roomId, userId, userAttrs, auth, token) {
    return await http.post(
      `https://api.agora.io/edu/v1/apps/${appid}/room/${roomId}/user/${userId}`,
      userAttrs,
      res => {
        return res.data
      },
      {},
      false,
      {
        headers: {
          Authorization: auth,
          token: token
        }
      }
    )
  },
  // 更新课程状态
  async updateCourse(appid, roomId, room, auth, token) {
    return await http.post(
      `https://api.agora.io/edu/v1/apps/${appid}/room/${roomId}`,
      room,
      res => {
        return res.data
      },
      {},
      false,
      {
        headers: {
          Authorization: auth,
          token: token
        }
      }
    )
  },
  // 退出房间
  async exitRoom(appid, roomId, auth, token) {
    return await http.post(
      `https://api.agora.io/edu/v1/apps/${appid}/room/${roomId}/exit`,
      {
        appId: appid,
        roomId: roomId
      },
      res => {
        return res.data
      },
      {},
      false,
      {
        headers: {
          Authorization: auth,
          token: token
        }
      }
    )
  },
  // 学生发起连麦申请
  async studentSendApply(appid, roomId, auth, token) {
    return await http.post(
      `https://api.agora.io/edu/v1/apps/${appid}/room/${roomId}/covideo`,
      {
        type: 1
      },
      res => {
        return res.data
      },
      {},
      false,
      {
        headers: {
          Authorization: auth,
          token: token
        }
      }
    )
  },
  // 学生主动取消连麦申请
  async studentStopCoVideo(appid, roomId, auth, token) {
    return await http.post(
      `https://api.agora.io/edu/v1/apps/${appid}/room/${roomId}/covideo`,
      {
        type: 6
      },
      res => {
        return res.data
      },
      {},
      false,
      {
        headers: {
          Authorization: auth,
          token: token
        }
      }
    )
  },
  // 教师同意学生申请
  async teacherAcceptApply(appid, roomId, userId, auth, token) {
    return await http.post(
      `https://api.agora.io/edu/v1/apps/${appid}/room/${roomId}/covideo`,
      {
        type: 4,
        userIds: [userId]
      },
      res => {
        return res.data
      },
      {},
      false,
      {
        headers: {
          Authorization: auth,
          token: token
        }
      }
    )
  },

  // 教师拒绝学生连麦
  async teacherRejectApply(appid, roomId, userId, auth, token) {
    return await http.post(
      `https://api.agora.io/edu/v1/apps/${appid}/room/${roomId}/covideo`,
      {
        type: 2,
        userIds: [userId]
      },
      res => {
        return res.data
      },
      {},
      false,
      {
        headers: {
          Authorization: auth,
          token: token
        }
      }
    )
  },
  // 教师取消学生连麦
  async teacherCancelStudent(appid, roomId, userId, auth, token) {
    return await http.post(
      `https://api.agora.io/edu/v1/apps/${appid}/room/${roomId}/covideo`,
      {
        type: 5,
        userIds: [userId]
      },
      res => {
        return res.data
      },
      {},
      false,
      {
        headers: {
          Authorization: auth,
          token: token
        }
      }
    )
  },

  // cc大班课创建直播间
  setLiveCczbRoomCreate(params, response) {
    return http.post('/course/live/cczb/room/create', params, response, {}, false)
  },

  // cc小班课创建直播间
  setLiveCcktRoomCreate(params, response) {
    return http.post('/course/live/cckt/room/create', params, response, {}, false)
  }
})
